package me.shiqiang.im.linsteners;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.annotation.OnEvent;
import me.shiqiang.im.enums.MessageCmd;
import me.shiqiang.im.msg.SyncFriendResp;
import me.shiqiang.im.server.ConnectionContext;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author cuishiqiang
 * @date 2018/1/15 上午9:36
 */
@Component("SyncFriendRespListener")
public class SyncFriendRespListener extends Listener{


    @OnEvent(MessageCmd.SYNC_FRIEND_RESP)
    public void resp(SocketIOClient client, SyncFriendResp resp) {
        Long userId = resp.getUserId();
        String clientId = ConnectionContext.getInstance().get(userId.toString());
        SocketIOClient userClient = server.getClient(UUID.fromString(clientId));
        if (userClient == null) {
            return;
        }
        userClient.sendEvent(MessageCmd.SYNC_FRIEND_RESP, resp);
    }
}
